package com.skywork.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.skywork.controller.request.CommonDataViewRequest;
import com.skywork.dao.CommonDataMapper;
import com.skywork.domain.CommonData;
import com.skywork.service.base.BaseService;

@Service
public class CommonDataService extends BaseService<CommonData> {

	@Autowired
	private CommonDataMapper commonDataMapper;

	@SuppressWarnings("rawtypes")
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public Page queryDynamicSQL(CommonData commonData, CommonDataViewRequest request) {
		PageHelper.startPage(request.getPageNum(), request.getPageSize());
		Page result = (Page) commonDataMapper.queryDynamicSQL(commonData.getHql(), request.getParam());
		return result;
	}

	public Page<CommonData> getList(Long channelId, int pageNum, int pageSize) {
		CommonData commonData = new CommonData();
		commonData.setChannelId(channelId);
		PageHelper.startPage(pageNum, pageSize);
		Page<CommonData> commonDataPage = (Page<CommonData>) commonDataMapper.select(commonData);
		PageHelper.clearPage();
		return commonDataPage;
	}
}
